a tool for shared writing and social publishing
1import { supabaseServerClient } from "supabase/serverClient";
2import { PublishPost } from "./PublishPost";
3import { PubLeafletPublication } from "lexicons/api";
4import { getIdentityData } from "actions/getIdentityData";
5
6import { AtpAgent } from "@atproto/api";
7import { ReplicacheProvider } from "src/replicache";
8
9export const preferredRegion = ["sfo1"];
10export const dynamic = "force-dynamic";
11export const fetchCache = "force-no-store";
12
13type Props = {
14 // this is now a token id not leaflet! Should probs rename
15 params: Promise<{ leaflet_id: string }>;
16};
17export default async function PublishLeafletPage(props: Props) {
18 let leaflet_id = (await props.params).leaflet_id;
19 let { data } = await supabaseServerClient
20 .from("permission_tokens")
21 .select(
22 `*,
23 permission_token_rights(*),
24 leaflets_in_publications(
25 *,
26 publications(
27 *,
28 documents_in_publications(count)
29 ),
30 documents(*))`,
31 )
32 .eq("id", leaflet_id)
33 .single();
34 let rootEntity = data?.root_entity;
35 if (!data || !rootEntity || !data.leaflets_in_publications[0])
36 return (
37 <div>
38 missin something
39 <pre>{JSON.stringify(data, undefined, 2)}</pre>
40 </div>
41 );
42
43 let identity = await getIdentityData();
44 if (!identity || !identity.atp_did) return null;
45 let pub = data.leaflets_in_publications[0];
46 let agent = new AtpAgent({ service: "https://public.api.bsky.app" });
47
48 let profile = await agent.getProfile({ actor: identity.atp_did });
49 return (
50 <ReplicacheProvider
51 rootEntity={rootEntity}
52 token={data}
53 name={rootEntity}
54 initialFacts={[]}
55 >
56 <PublishPost
57 leaflet_id={leaflet_id}
58 root_entity={rootEntity}
59 profile={profile.data}
60 title={pub.title}
61 publication_uri={pub.publication}
62 description={pub.description}
63 record={pub.publications?.record as PubLeafletPublication.Record}
64 posts_in_pub={pub.publications?.documents_in_publications[0].count}
65 />
66 </ReplicacheProvider>
67 );
68}